﻿using System;
using System.Windows.Forms;
using DevExpress.XtraSplashScreen;

namespace XCI.Helper
{
    /// <summary>
    /// 等待窗体管理
    /// </summary>
    public static class WaitFormHelper
    {
        /// <summary>
        /// 等待窗体对象类型
        /// </summary>
        public static Type WaitFormType { get; private set; }

        /// <summary>
        /// 设置等待窗体对象类型
        /// </summary>
        /// <param name="waitFormType">等待窗体对象类型</param>
        public static void SetWaitFormType(Type waitFormType)
        {
            WaitFormType = waitFormType;
        }

        /// <summary>
        /// 显示Wait页面
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="ownerForm">所属窗体</param>
        public static void Show(string msg,Form ownerForm = null)
        {
            if (WaitFormType == null) return;

            if (SplashScreenManager.Default == null)
            {
                SplashScreenManager.ShowForm(ownerForm, WaitFormType, true, true);
            }
            if (!string.IsNullOrEmpty(msg) && SplashScreenManager.Default != null)
            {
                SplashScreenManager.Default.SendCommand(WaitCommand.Msg, msg);
            }
        }

        /// <summary>
        /// 隐藏Wait页面
        /// </summary>
        public static void Hide()
        {
            SplashScreenManager.CloseForm(false);
        }
    }

    /// <summary>
    /// 等待窗体命令类型
    /// </summary>
    public enum WaitCommand
    {
        Msg
    }
}
